//
// Created by jm on 2022/1/20.
//

#include <mutex>
#include <iostream>
#include <utility>
#include "timer.h"


int64_t GetTimestamp(){
  auto timestamp =
      std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
  return timestamp;
}
Timer::Timer(std::string name) : name_(std::move(name)) {
  start_ = GetTimestamp();
}
Timer::~Timer() {
  end_ = GetTimestamp();
  std::cout<<"[Timer]:"<<name_<<"cost " <<end_- start_<<" ms ."<<std::endl;
}
std::string GetPathOrURLShortName(std::string strFullName) {
  if (strFullName.empty()) {
    return "";
  }

  string_replace(strFullName, "/", "\\");

  std::string::size_type iPos = strFullName.find_last_of('\\') + 1;

  return strFullName.substr(iPos, strFullName.length() - iPos);
}
void string_replace(std::string &strBig, const std::string &strsrc, const std::string &strdst) {
  std::string::size_type pos = 0;
  std::string::size_type srclen = strsrc.size();
  std::string::size_type dstlen = strdst.size();

  while ((pos = strBig.find(strsrc, pos)) != std::string::npos) {
    strBig.replace(pos, srclen, strdst);
    pos += dstlen;
  }
}
